/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cdp.cdf.component.metadata.serializer;

import com.fasterxml.jackson.databind.JsonNode;
import com.inspur.edp.cdp.cdf.component.manager.serializer.CompOperationSerializer;
import com.inspur.edp.cdp.cdf.component.manager.serializer.ComponentSerializer;
import com.inspur.edp.cdp.cdf.component.metadata.CommonComponentMetadata;
import com.inspur.edp.component.schema.AbstractComponent;
import com.inspur.edp.component.schema.resource.BeanResource;

public class CommonComponentSerializer extends ComponentSerializer {

    @Override
    protected void readExtendInfo(AbstractComponent comp, JsonNode jsonNode) {
        //兼容历史Bean类型的数据
        if (comp.getResource() == null) {
            BeanResource beanResource = new BeanResource();
            //N版历史元数据可能反序列化不到内容，设计期已不支持，但运行时需要支持，在调用接口处处理
            beanResource.setBeanName(comp.getId());
            comp.setResource(beanResource);
        }
    }

    @Override
    protected void writeExtendInfo(AbstractComponent comp, JsonNode jsonNode) {

    }

    @Override
    protected AbstractComponent createComponent() {
        return new CommonComponentMetadata();
    }

    @Override
    protected CompOperationSerializer getOperationSerializer() {
        return new CommonCompOperationSerializer();
    }
}
